﻿/*
#**************************************************************************
#  openSIS is a student information system for public and non-public 
#  schools from Open Solutions for Education, Inc. web: www.os4ed.com
#
#  openSIS is  web-based, open source, and comes packed with features that 
#  include student demographic info, scheduling, grade book, attendance, 
#  report cards, eligibility, transcripts, parent portal, 
#  student portal and more.   
#
#  Visit the openSIS web site at http://www.opensis.com to learn more.
#  If you have question regarding this system or the license, please send 
#  an email to info@os4ed.com.
#
#  This program is released under the terms of the GNU General Public License  
#  as  published by the Free Software Foundation, version 2 of the License. 
#  See license.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#**************************************************************************** 

*/

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using OpenSISSchoolDataLayer;


namespace OpensisSchoolBusinessLayer
{
    public class SchoolBL
    {
        private int schoolid;
        private string schoolname;
        private string shortname;
        private string address1;
        private string address2;
        private int state;
        private string city;
        private string zip;
        private string fax;
        private string phone;
        private string url;
        private int ceeb;
        private string type;
        private string level;
        private int mingrade;
        private int maxgrade;
        private string postzip;
        private int poststate;
        private string postcity;
        private string postbox;
        private string emerphone;
        private string lastupdated;
        private string maxgradename;
        private string mingradename;
        private string email;
        private string principal;
        private string basegradingscale;
        private int schyryear;
        private int schcountry;
        private string statename;
        private string poststatename;
        private string countryname;

        private int postboxcountry;
        private string postboxaddress1;
        private string postboxaddress2;
        private string postcountryname;


        public SchoolBL()
        {
            postboxcountry = 0;
            postboxaddress1 = "";
            postboxaddress2 = "";


            schoolid = 0;
            schoolname = "";
            shortname = "";
            address1 = "";
            address2 = "";
            state = 0;
            city = "";
            zip = "";
            fax = "";
            phone = "";
            url = "";
            ceeb = 0;
            type = "";
            level = "";
            mingrade = 0;
            maxgrade = 0;
            postzip = "";
            poststate = 0;
            postcity = "";
            postbox = "";
            emerphone = "";
            lastupdated = "";
            maxgradename = "";
            mingradename = "";
            email = "";
            principal = "";
            basegradingscale = "";
            schyryear = 0;
            schcountry = 0;
            statename = "";
            poststatename = "";
            countryname = "";
            postcountryname = "";
        }

        public int SchoolID
        {
            get
            {
                return this.schoolid;
            }
            set
            {
                this.schoolid = value;
            }
        }

        public String SchoolName
        {
            get
            {
                return this.schoolname;
            }
            set
            {
                this.schoolname = value;

            }
        }

        public String ShortName
        {
            get
            {
                return this.shortname;
            }
            set
            {
                this.shortname = value;

            }
        }

        public String Address1
        {
            get
            {
                return this.address1;
            }
            set
            {
                this.address1 = value;

            }
        }

        public String Address2
        {
            get
            {
                return this.address2;
            }
            set
            {
                this.address2 = value;

            }
        }

        public String City
        {
            get
            {
                return this.city;
            }
            set
            {
                this.city = value;

            }
        }

        public int State
        {
            get
            {
                return this.state;
            }
            set
            {
                this.state = value;

            }
        }

        public String Zip
        {
            get
            {
                return this.zip;
            }
            set
            {
                this.zip = value;

            }
        }

        public String Fax
        {
            get
            {
                return this.fax;
            }
            set
            {
                this.fax = value;

            }
        }

        public String Phone
        {
            get
            {
                return this.phone;
            }
            set
            {
                this.phone = value;

            }
        }

        public String Url
        {
            get
            {
                return this.url;
            }
            set
            {
                this.url = value;

            }
        }

        public int CeebNum
        {
            get
            {
                return this.ceeb;
            }
            set
            {
                this.ceeb = value;

            }
        }

        public String Type
        {
            get
            {
                return this.type;
            }
            set
            {
                this.type = value;

            }
        }

        public String Level
        {
            get
            {
                return this.level;
            }
            set
            {
                this.level = value;

            }
        }

        public int MinGrade
        {
            get
            {
                return this.mingrade;
            }
            set
            {
                this.mingrade = value;

            }
        }

        public int MaxGrade
        {
            get
            {
                return this.maxgrade;
            }
            set
            {
                this.maxgrade = value;

            }
        }

        public String PostZip
        {
            get
            {
                return this.postzip;
            }
            set
            {
                this.postzip = value;

            }
        }

        public int PostState
        {
            get
            {
                return this.poststate;
            }
            set
            {
                this.poststate = value;

            }
        }

        public String PostCity
        {
            get
            {
                return this.postcity;
            }
            set
            {
                this.postcity = value;

            }
        }

        public String PostBox
        {
            get
            {
                return this.postbox;
            }
            set
            {
                this.postbox = value;

            }
        }

        public String EmerPhone
        {
            get
            {
                return this.emerphone;
            }
            set
            {
                this.emerphone = value;

            }
        }

        public String LastUpdated
        {
            get
            {
                return this.lastupdated;
            }
            set
            {
                this.lastupdated = value;

            }
        }

        public String MaxGradeName
        {
            get
            {
                return this.maxgradename;
            }
            set
            {
                this.maxgradename = value;

            }
        }
        public String MinGradeName
        {
            get
            {
                return this.mingradename;
            }
            set
            {
                this.mingradename = value;

            }
        }

        public String Email
        {
            get
            {
                return this.email;
            }
            set
            {
                this.email = value;

            }
        }


        public String Principal
        {
            get
            {
                return this.principal;
            }
            set
            {
                this.principal = value;

            }
        }

        public String BaseGradeScale
        {
            get
            {
                return this.basegradingscale;
            }
            set
            {
                this.basegradingscale = value;

            }
        }

        public int SchyrYear
        {
            get
            {
                return this.schyryear;
            }
            set
            {
                this.schyryear = value;
            }
        }

        public int Country
        {
            get
            {
                return this.schcountry;
            }
            set
            {
                this.schcountry = value;
            }
        }


        public String StateName
        {
            get
            {
                return this.statename;
            }
            set
            {
                this.statename = value;

            }
        }

        public String PostStateName
        {
            get
            {
                return this.poststatename;
            }
            set
            {
                this.poststatename = value;

            }
        }

        public String CountryName
        {
            get
            {
                return this.countryname;
            }
            set
            {
                this.countryname = value;

            }
        }


        public String PostBoxAddress1
        {
            get
            {
                return this.postboxaddress1;
            }
            set
            {
                this.postboxaddress1 = value;

            }
        }


        public String PostBoxAddress2
        {
            get
            {
                return this.postboxaddress2;
            }
            set
            {
                this.postboxaddress2 = value;

            }
        }



        public int PostBoxCountry
        {
            get
            {
                return this.postboxcountry;
            }
            set
            {
                this.postboxcountry = value;
            }
        }

        public String PostCountryName
        {
            get
            {
                return this.postcountryname;
            }
            set
            {
                this.postcountryname = value;

            }
        }



        public void SchoolAdd()
        {
            SchoolDL scDl = new SchoolDL();
            scDl.SchoolAdd(this);
        }

        public void SchoolEdit()
        {
            SchoolDL scDl = new SchoolDL();
            scDl.SchoolEdit(this);
        }

        public System.Data.DataTable SearchSchool()
        {
            DataTable dt = null;
            SchoolDL scDl = new SchoolDL();
            dt = scDl.SearchSchoolDetails(this);
            return dt;
        }

        public void MaxSchoolID()
        {
            DataTable dt = null;
            SchoolDL scDl = new SchoolDL();
            dt = scDl.PopulateMaxSchoolID();
            schoolid = Convert.ToInt32(dt.Rows[0][0]);

        }

        //public void GetvalufromID()
        //{
        //    SchoolDL scDl = new SchoolDL();
        //    DataTable dt = scDl.SchoolDetailsByID(this);
        //    if (dt.Rows.Count > 0)
        //    {
        //        schoolid = Convert.ToInt32(dt.Rows[0][0]);
        //        shortname = dt.Rows[0]["sch_short_nm"].ToString().Trim();
        //        schoolname = dt.Rows[0]["sch_full_nm"].ToString().Trim();
        //        address1 = dt.Rows[0]["sch_addr1"].ToString().Trim();
        //        address2 = dt.Rows[0]["sch_addr2"].ToString().Trim();
        //        city = dt.Rows[0]["sch_city"].ToString().Trim();
        //        statename = dt.Rows[0]["State"].ToString().Trim();
        //        zip = dt.Rows[0]["sch_zip"].ToString().Trim();
        //        fax = dt.Rows[0]["sch_fax"].ToString().Trim();
        //        phone = dt.Rows[0]["sch_phn"].ToString().Trim();
        //        url = dt.Rows[0]["sch_url"].ToString().Trim();
        //        ceeb = Convert.ToInt32(dt.Rows[0]["sch_ceeb_nbr"]);
        //        type = dt.Rows[0]["sch_type"].ToString().Trim();
        //        level = dt.Rows[0]["sch_ed_lvl"].ToString().Trim();
        //        mingrade = Convert.ToInt32(dt.Rows[0]["sch_min_grade_id"]);
        //        maxgrade = Convert.ToInt32(dt.Rows[0]["sch_max_grade_id"]);
        //        mingradename = dt.Rows[0]["MinGrade"].ToString().Trim();
        //        maxgradename = dt.Rows[0]["MaxGrade"].ToString().Trim();
        //        postzip = dt.Rows[0]["sch_po_box_zip"].ToString().Trim();
        //        poststatename = dt.Rows[0]["PostState"].ToString().Trim();
        //        postcity = dt.Rows[0]["sch_po_box_city"].ToString().Trim();
        //        postbox = dt.Rows[0]["sch_po_box"].ToString().Trim();
        //        emerphone = dt.Rows[0]["sch_emer_phn"].ToString().Trim();
        //        email = dt.Rows[0]["sch_email"].ToString().Trim();
        //        principal = dt.Rows[0]["sch_principal"].ToString().Trim(); ;
        //        basegradingscale = dt.Rows[0]["sch_base_grading_scale"].ToString().Trim();
        //        countryname = dt.Rows[0]["Country"].ToString().Trim();

        //        postcountryname = dt.Rows[0]["PostCountry"].ToString().Trim();

        //        postboxaddress1 = dt.Rows[0]["sch_po_box_addr1"].ToString().Trim();
        //        postboxaddress2 = dt.Rows[0]["sch_po_box_addr2"].ToString().Trim();
        //    }
        //}





        public DataTable GetvalufromID()
        {
            SchoolDL scDl = new SchoolDL();
            DataTable dt = scDl.SchoolDetailsByID(this);
            return dt;
           
        }




        //public void propulate(ref System.Web.UI.WebControls.DropDownList ddl)
        //{
        //    string s = System.Web.HttpContext.Current.Session["MLCulture"].ToString();

        //    string select = "";

        //    switch (s)
        //    {
        //        case "en-US":
        //            select = "Select";

        //            break;
        //        case "es-MX":
        //            select = "Seleccione";

        //            break;
        //        case "zh-CN":
        //            select = "选择";

        //            break;
        //        case "ja-JP":
        //            select = "を選択";

        //            break;
        //        case "de-DE":
        //            select = "Wählen Sie";

        //            break;
        //        case "ko-KR":
        //            select = "선택";

        //            break;
        //        case "fr-FR":
        //            select = "Sélectionnez";

        //            break;
        //        case "it-IT":
        //            select = "Seleziona";

        //            break;
        //        case "ru-RU":
        //            select = "Выберите";

        //            break;
        //        case "pt-BR":
        //            select = "Seleccione";

        //            break;
        //        case "ar-SA":
        //            select = "رتخا";

        //            break;
        //    }


        //    SchoolDL scDl = new SchoolDL();
        //    ddl.Items.Clear();
        //    DataSet ds = null;
        //    ds = scDl.PopulateGrade(this);
        //    ddl.DataSource = ds.Tables[0];
        //    ddl.DataTextField = "grd_lvl_short_nm";//saikat----14/5/09
        //    ddl.DataValueField = "grd_lvl_id";//saikat----14/5/09
        //    ddl.DataBind();
        //    ddl.Items.Insert(0, new ListItem(select, "0"));


        //}


        public DataSet propulate()
        {
            

            SchoolDL scDl = new SchoolDL();
        
            DataSet ds = null;

            ds = scDl.PopulateGrade(this);
            return ds;


        }







        public void propulateState(ref System.Web.UI.WebControls.DropDownList ddl)
        {
            string s = System.Web.HttpContext.Current.Session["MLCulture"].ToString();

            string select = "";

            switch (s)
            {
                case "en-US":
                    select = "Select";

                    break;
                case "es-MX":
                    select = "Seleccione";

                    break;
                case "zh-CN":
                    select = "选择";

                    break;
                case "ja-JP":
                    select = "を選択";

                    break;
                case "de-DE":
                    select = "Wählen Sie";

                    break;
                case "ko-KR":
                    select = "선택";

                    break;
                case "fr-FR":
                    select = "Sélectionnez";

                    break;
                case "it-IT":
                    select = "Seleziona";

                    break;
                case "ru-RU":
                    select = "Выберите";

                    break;
                case "pt-BR":
                    select = "Seleccione";

                    break;
                case "ar-SA":
                    select = "رتخا";

                    break;
            }


            SchoolDL scDl = new SchoolDL();
            ddl.Items.Clear();
            DataSet ds = null;
            ds = scDl.PopulateState();
            ddl.DataSource = ds.Tables[0];
            ddl.DataTextField = "NAME";
            ddl.DataValueField = "IID";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem(select, "0"));


        }
        public void propulateSchool(ref System.Web.UI.WebControls.DropDownList ddl)
        {

            string s = System.Web.HttpContext.Current.Session["MLCulture"].ToString();

            string select = "";

            switch (s)
            {
                case "en-US":
                    select = "Select";

                    break;
                case "es-MX":
                    select = "Seleccione";

                    break;
                case "zh-CN":
                    select = "选择";

                    break;
                case "ja-JP":
                    select = "を選択";

                    break;
                case "de-DE":
                    select = "Wählen Sie";

                    break;
                case "ko-KR":
                    select = "선택";

                    break;
                case "fr-FR":
                    select = "Sélectionnez";

                    break;
                case "it-IT":
                    select = "Seleziona";

                    break;
                case "ru-RU":
                    select = "Выберите";

                    break;
                case "pt-BR":
                    select = "Seleccione";

                    break;
                case "ar-SA":
                    select = "رتخا";

                    break;
            }





            SchoolDL scDl = new SchoolDL();
            ddl.Items.Clear();
            DataSet ds = null;
            ds = scDl.PopulateSchool();
            ddl.DataSource = ds.Tables[0];
            ddl.DataTextField = "sch_full_nm";
            ddl.DataValueField = "sch_id";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem(select, "0"));


        }

        //public void PopulateFullYear(ref System.Web.UI.WebControls.DropDownList ddl)
        //{
        //    SchoolDL scDl = new SchoolDL();
        //    ddl.Items.Clear();
        //    DataSet ds = null;
        //    ds = scDl.PopulateFullYear(this);
        //    ddl.DataSource = ds.Tables[0];
        //    ddl.DataTextField = "sch_mp_name";
        //    ddl.DataValueField = "schyr_id";
        //    ddl.DataBind();
        //    ddl.Items.Insert(0, new ListItem("Select", "0"));


        //}


        public void PopulateFullYear(ref System.Web.UI.WebControls.DropDownList ddl, ref System.Web.UI.WebControls.DropDownList ddl1)
        {
            string s = System.Web.HttpContext.Current.Session["MLCulture"].ToString();

            string select = "";

            switch (s)
            {
                case "en-US":
                    select = "Select";

                    break;
                case "es-MX":
                    select = "Seleccione";

                    break;
                case "zh-CN":
                    select = "选择";

                    break;
                case "ja-JP":
                    select = "を選択";

                    break;
                case "de-DE":
                    select = "Wählen Sie";

                    break;
                case "ko-KR":
                    select = "선택";

                    break;
                case "fr-FR":
                    select = "Sélectionnez";

                    break;
                case "it-IT":
                    select = "Seleziona";

                    break;
                case "ru-RU":
                    select = "Выберите";

                    break;
                case "pt-BR":
                    select = "Seleccione";

                    break;
                case "ar-SA":
                    select = "رتخا";

                    break;
            }



            SchoolDL scDl = new SchoolDL();
            ddl.Items.Clear();
            DataSet ds = null;
            ds = scDl.PopulateFullYear(this);
            ddl.DataSource = ds.Tables[0];
            ddl.DataTextField = "schyr_nm";
            ddl.DataValueField = "schyr_id";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem(select, "0"));


            //**********************************************
            ddl1.Items.Clear();
            DataSet dsSemester = null;
            if (ds.Tables[0].Rows.Count == 0)
            {
                SchyrYear = Convert.ToInt32("0");
            }
            else
            {
                SchyrYear = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            }
            dsSemester = scDl.PopulateLevel1(this);
            ddl1.DataSource = dsSemester.Tables[0];
            ddl1.DataTextField = "sch_mp_name";
            ddl1.DataValueField = "schyr_id";
            ddl1.DataBind();
            ddl1.Items.Insert(0, new ListItem(select, "0"));
            ddl.Items.FindByValue(Convert.ToString(SchyrYear)).Selected = true;
            if (dsSemester.Tables[0].Rows.Count > 0)
            {
                ddl1.Items.FindByValue(Convert.ToString(dsSemester.Tables[0].Rows[0][0])).Selected = true;
            }

        }


        public void PopulateLevel1(ref System.Web.UI.WebControls.DropDownList ddl)
        {
            string s = System.Web.HttpContext.Current.Session["MLCulture"].ToString();

            string select = "";

            switch (s)
            {
                case "en-US":
                    select = "Select";

                    break;
                case "es-MX":
                    select = "Seleccione";

                    break;
                case "zh-CN":
                    select = "选择";

                    break;
                case "ja-JP":
                    select = "を選択";

                    break;
                case "de-DE":
                    select = "Wählen Sie";

                    break;
                case "ko-KR":
                    select = "선택";

                    break;
                case "fr-FR":
                    select = "Sélectionnez";

                    break;
                case "it-IT":
                    select = "Seleziona";

                    break;
                case "ru-RU":
                    select = "Выберите";

                    break;
                case "pt-BR":
                    select = "Seleccione";

                    break;
                case "ar-SA":
                    select = "رتخا";

                    break;
            }


            SchoolDL scDl = new SchoolDL();
            ddl.Items.Clear();
            DataSet ds = null;
            ds = scDl.PopulateLevel1(this);
            ddl.DataSource = ds.Tables[0];
            ddl.DataTextField = "sch_mp_name";
            ddl.DataValueField = "schyr_id";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem(select, "0"));


        }

        //****************************(08/07/09)*********************
        public void propulateCountry(ref System.Web.UI.WebControls.DropDownList ddl)
        {

            string s = System.Web.HttpContext.Current.Session["MLCulture"].ToString();

            string select = "";

            switch (s)
            {
                case "en-US":
                    select = "Select";

                    break;
                case "es-MX":
                    select = "Seleccione";

                    break;
                case "zh-CN":
                    select = "选择";

                    break;
                case "ja-JP":
                    select = "を選択";

                    break;
                case "de-DE":
                    select = "Wählen Sie";

                    break;
                case "ko-KR":
                    select = "선택";

                    break;
                case "fr-FR":
                    select = "Sélectionnez";

                    break;
                case "it-IT":
                    select = "Seleziona";

                    break;
                case "ru-RU":
                    select = "Выберите";

                    break;
                case "pt-BR":
                    select = "Seleccione";

                    break;
                case "ar-SA":
                    select = "رتخا";

                    break;
            }

            SchoolDL scDl = new SchoolDL();
            ddl.Items.Clear();
            DataSet ds = null;
            ds = scDl.PopulateCountry();
            ddl.DataSource = ds.Tables[0];
            ddl.DataTextField = "NAME";
            ddl.DataValueField = "IID";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem(select, "0"));


        }

        public void UpdateMaxGrade()
        {
            SchoolDL scDl = new SchoolDL();
            scDl.UpdateMaxGrade(this);
        }
        public void UpdateMinGrade()
        {
            SchoolDL scDl = new SchoolDL();
            scDl.UpdateMinGrade(this);
        }

    }
}
